from PyQt5 import QtWidgets

class SearchWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(SearchWidget, self).__init__()
        self.parent = parent
        self.initUI()

    def initUI(self):
        self.hbox = QtWidgets.QHBoxLayout()
        self.hbox.setContentsMargins(0, 0, 10, 0)
        self.hbox.setSpacing(0)
        self.edit = QtWidgets.QLineEdit(self)
        self.btn = QtWidgets.QPushButton("搜索", self)
        self.hbox.addWidget(self.edit)
        self.hbox.addWidget(self.btn)
        self.hbox.setSpacing(0)
        self.setLayout(self.hbox)
        self.edit.editingFinished.connect(self.btn.click)
        self.btn.clicked.connect(self.do_search)

    def do_search(self):
        text = self.edit.text()
        if not text: return
        self.parent.tableWidget.scrollAndHighlight(text)